import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static int MOD = 109;

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();

        int ret = n;
        for(int i = 0; i < m - 1; i++){
            ret = ret * (n - 1) % MOD;
        }
        System.out.println(ret);
    }

    //
    public static int N = 1010;
    public static int[] dx = {0,0,1,-1};
    public static int[] dy = {1,-1,0,0};

    public static int n, m, x1, y1, x2, y2;
    public static char[][] arr = new char[N][N];
    public static int[][] dist = new int[N][N];

    public static int bfs(){

        if(arr[x2][y2] == '*') { return -1;}

        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                dist[i][j] = -1;
            }
        }

        Queue<int[]> q = new LinkedList<>();
        q.add(new int[]{x1, y1});
        dist[x1][y1] = 0;

        while(!q.isEmpty()){
            int[] t = q.poll();
            int a = t[0], b = t[1];
            for(int i = 0; i < 4; i++){
                int x = a + dx[i], y = b + dy[i];
                if(x >= 1 && x <= n && y >= 1 && y <= m && arr[x][y] == '.' && dist[x][y] == -1){
                    q.add(new int[]{x, y});
                    dist[x][y] = dist[a][b] + 1;
                    if(x == x2 && y == y2){
                        return dist[x][y];
                    }
                }
            }
        }
        return -1;
    }
}
